<?php
if(isset($_GET["decatid"]))
{
	$deid=$_GET['decatid'];
	$db->query("delete from ".CUSTOM_CAT." where id='$deid'");
	
	$sql="select relating_id from ".CUSTOM_CAT_REL." where custom_cat_id='$deid'";
	$db->query($sql);
	$arrid=$db->getRows();
	foreach($arrid as $v)
	{
		$id=$v['relating_id'];
		$db->query("delete from ".ALBUM." where id='$id'");
		@unlink($config['webroot']."/uploadfile/zsimg/size_small/$id.jpg");
		@unlink($config['webroot']."/uploadfile/zsimg/$id.jpg");
	}
	@unlink($config['webroot']."/uploadfile/catimg/size_small/$deid.jpg");
	$sql="delete from ".CUSTOM_CAT_REL." where custom_cat_id='$deid'";
	$db->query($sql);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<HEAD>
<TITLE><?php echo lang_show('admin_system');?></TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">
<link href="main.css" rel="stylesheet" type="text/css" />
</HEAD>
<body>
<div class="bigbox">
	<div class="bigboxhead"><?php echo lang_show('album');?></div>
	<div class="bigboxbody">
  <table width="100%" border="0" cellpadding="2" cellspacing="0">
      <tr class="theader"> 
      <td width="10%" ><?php echo lang_show('album_cat_cover');?></td>
      <td width="20%" ><?php echo lang_show('album_cat_name');?></td>
      <td width="*%" ><?php echo lang_show('cat_c');?></td>
      <td width="25%" ><?php echo lang_show('poster');?></td>
      <td width="18%" align="center" ><?php echo lang_show('manager');?></td>
      </tr>
    <?php
	$sql=NULL;
		if(!empty($_GET["keyword"]))
			$sql=" and a.name like '%$_GET[keyword]%' ";
		if($_SESSION["province"])
			$sql.=" and b.province='$_SESSION[province]'";
		if($_SESSION["city"])
			$sql.=" and b.city='$_SESSION[city]'";
		$sql="SELECT 
				a.id,a.tj,a.name,a.des,b.company,a.pic FROM ".CUSTOM_CAT." a,".USER." b 
			  WHERE a.userid=b.userid and a.type=6 $sql ORDER BY a.ID DESC";
		//=============================
		include_once("../includes/page_utf_class.php");
	  	$page = new Page;
		$page->listRows=10;
		if (!$page->__get('totalRows')){
			$db->query($sql);
			$page->totalRows = $db->num_rows();
		}
        $sql .= "  limit ".$page->firstRow.",20";
		$pages = $page->prompt();
		//==================================
	$db->query($sql);
	$re=$db->getRows();
	$count_num=count($re);
	for($i=0;$i<$count_num;$i++)
	{
	?> 
         <tr> 
         <td><?php if($re[$i]['pic']){?><img src="../<?php echo $re[$i]['pic'];?>" width="70"><?php }else{?><img width="70" src="../image/default/nopic.gif" /><?php } ?></td>
         <td><a href="module.php?m=album&s=album.php&catid=<?php echo $re[$i]['id'];?>"><?php echo $re[$i]["name"];?></a>
		 (<?php
		$sql = "select count(1) as count from ".CUSTOM_CAT_REL." where custom_cat_id='".$re[$i]['id']."'";
		$db->query($sql);
		$row = $db->fetchRow();
		if($row['count']>0)
			echo $row['count'];
		else
			echo 0;
		?>)
		 </td>
         <td align="left"> <?php echo $re[$i]["des"]; ?></td>
         <td align="left"> <?php echo $re[$i]["company"]; ?></td>
         <td align="center">
		 <a href="module.php?m=album&s=album_cat.php&decatid=<?php echo $re[$i]["id"]; ?>" onClick="return confirm('<?php echo lang_show('are_you_sure');?>');"><?php echo $delimg;?></a>

		 </td>
        </tr>
    <?php 
    }
	?>
  </table>
  <div align="right"><div class="page"><?php echo $pages?></div></div>
  </div>
</div>
</body>
</html>
